package com.cd826dong.clouddemo.service;

import org.springframework.web.client.RestTemplate;

import com.netflix.hystrix.HystrixCommand;

public class HystrixCommandCacheService extends HystrixCommand<String> {

	private String name;
	private RestTemplate restTemplate;
	
	
	public HystrixCommandCacheService(Setter setter, RestTemplate restTemplate, String name) {
		super(setter);
		this.name = name;
		this.restTemplate = restTemplate;
	}

	@Override
	protected String run() throws Exception {
		 return restTemplate.getForEntity("http://localhost:2100/hello/rand/num", String.class).getBody();
	}
	
	@Override
	protected String getFallback() {
		return "fall back use HystrixCommand method," + name;
	}
	
	@Override
	protected String getCacheKey() {
		return "cache";
	}

}
